<!DOCTYPE html>
<html>

{include file='public/header'}

<style>
    .layui-table-cell {
        height: auto!important;
    }
</style>
<body>
    <div class="x-nav">
        <span class="layui-breadcrumb">
            <a href="javascript:void(0)">首页</a>
            <a href="javascript:void(0)">分销</a>
            <a><cite>分销商分成统计</cite></a>
        </span>
        <a class="layui-btn layui-btn-small" id="reload" title="刷新">
            <i class="layui-icon" style="line-height:30px"><i class="iconfont">&#xe6aa;</i></i>
        </a>
    </div>
    <div class="x-body">
        <div class="layui-row">
            <form class="layui-form" lay-filter="searchForm">
                <div class="layui-inline">
                    <label class="layui-form-label w-auto">日期：</label>
                    <div class="layui-inline" id="time" style="display: flex;align-items: center;">
                        <div class="layui-input-inline" style="margin-right:10px">
                            <input type="text" class="layui-input" name="start_date" id="start_time" autocomplete="off"
                                placeholder="开始时间">
                        </div>
                        <div class="layui-form-mid">-</div>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" name="end_date" id="end_time" autocomplete="off"
                                placeholder="结束日期">
                        </div>
                    </div>
                </div>
                <button class="layui-btn" style="margin-left: 10px;" lay-submit lay-filter="searchList">搜索</button>
                <button type="reset" id="resetList" class="layui-btn layui-btn-primary">重置</button>
            </form>
        </div>
        <table id="dividedStatisticsList" lay-filter="dividedStatisticsList"></table>
    </div>
    
    <script>
        let totalObj = {}
        let params = {
            elem: '#dividedStatisticsList'
            , toolbar: true
            , url: '/cps/distribution/dividedStatisticsList' //数据接口
            , id: 'dividedStatisticsList'
            , limit:15
            , page:true
            , totalRow:true
            , cols: [[ //表头
                { field: 'date', title: '日期', align:'center' ,totalRowText: '总合计：' }
                , { field: 'name', title: '负责人名称', align:'center' }
                , { field: 'company_name', title: '公司名称', align:'center' }
                , { field: 'recharge_price', title:'总充值金额', align:'center'}
                , { field: 'refund_price', title: '总退款金额', align:'center' }
                , { field: 'commission', title: '总支付通道费', align:'center', width:120 }
                , { field: 'virtual_recharge_price', title:'虚拟支付<br />充值金额', align:'center', width:140}
                , { field: 'virtual_refund_price', title:'虚拟支付<br />退款金额', align:'center', width:140}
                , { field: 'virtual_commission', title:'虚拟支付<br />通道费(0.8%)', align:'center', width:140}
                , { field: 'virtual_amount', title:'虚拟支付<br />分成金额(80%)', align:'center', width:140}
                , { field: 'common_recharge_price', title:'非虚拟支付<br />充值金额', align:'center', width:140}
                , { field: 'common_refund_price', title:'非虚拟支付<br />退款金额', align:'center', width:140}
                , { field: 'common_commission', title:'非虚拟支付<br />通道费(0.8%)', align:'center', width:140}
                , { field: 'common_amount', title:'非虚拟支付<br />分成金额(85%)', align:'center', width:140}
                , { field: 'sharing_amount', title: '分成后总金额', align:'center', width:140 }
            ]],
            customTotal:function(){
                let that = this;
                layui.use('form', function () {
                    getTotal('/cps/distribution/divideIntoTotal',totalObj).then(val=>{
                        totalObj = val
                    })
                });
            },
            done:function(){
                setPrice(totalObj)
            }
        }
        tableList(params)
        layui.use('laydate', function () {
            var laydate = layui.laydate;
            laydate.render({
                elem: '#time',
                range: ['#start_time', '#end_time'],
                format: 'yyyy-MM-dd'
            });

        })

        function setPrice(totalObj){
            Object.keys(totalObj).forEach(item=>{
                $(`.layui-table-total td[data-field=${item}] .layui-table-cell`).text(totalObj[item]);
            })
        }
    </script>
</body>

</html>